home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / contrib / nukeq / nukeq.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1991-10-26  |  3.1 KB  |  140 lines

  1. #!/bin/sh
  2. # @(#)contrib/nukeq/nukeq.sh    1.1 10/26/91 22:57:56
  3. #
  4. # Remail all of the mail queued for a particular system.  Run as
  5. #
  6. # nukeq <sysname>
  7. #
  8. # Does nothing unless the paths files have been rebuilt so that all
  9. # final destinations in the mail messages are now reached through a
  10. # different neighbor.  Otherwise mail will just be requeued for the
  11. # same system again.
  12. #
  13. # Doesn't fix the requestor field in the new X file, so errors in mailing
  14. # further along the line will probably be returned to the person who ran
  15. # nukeq rather then the person who originally sent the mail.
  16. #
  17. # The destinations are aggressively rerouted on the assumption that the
  18. # old path is irrelevant to the new first-hop.  This may result in mail
  19. # sent to an incorrect system with the same name as the correct system.
  20. #
  21. # If uucico starts up while this thing is running, the world will come
  22. # to an end.
  23.  
  24.  
  25. if [ `id|sed 's/^uid=\([0-9]*\).*$/\1/'` -ne 0 ]
  26. then
  27.     echo Not superuser, no can do.
  28.     exit
  29. fi
  30.  
  31. if [ $# -ne 1 ]
  32. then
  33.     echo Need a system name
  34.     exit
  35. fi
  36.  
  37. sysname=$1
  38.  
  39. cd /usr/spool/uucp/$sysname
  40.  
  41. for cfile in C.*
  42. do
  43.     (
  44.         echo Doing C-file $cfile
  45.  
  46.         # For each C-file
  47.         # Grab the line describing the D file
  48.  
  49.         read type source dest sender opts data mode notify || {
  50.             echo $cfile is empty, skipping...
  51.             continue
  52.         }
  53.  
  54.         if [ "$type" != "S" -o "$source" != "$data" \
  55.           -o "$sender" != "$notify" -o "$opts" != "-" ]
  56.         then
  57.             echo $cfile has invalid line 1, skipping...
  58.             continue
  59.         fi
  60.  
  61.         case $dest in
  62.             D.*)    ;;
  63.             *)    echo $cfile line 1 isn\'t a Dfile, skipping...
  64.                 continue
  65.                 ;;
  66.         esac
  67.  
  68.         dfile=$source
  69.         echo D-file is $dfile
  70.  
  71.         # Grab the line describing the X file
  72.         read type source dest sender opts data mode notify || {
  73.             echo $cfile missing line 2, skipping...
  74.             continue
  75.         }
  76.  
  77.         if [ "$type" != "S" -o "$source" != "$data" \
  78.           -o "$sender" != "$notify" -o "$opts" != "-" ]
  79.         then
  80.             echo $cfile has invalid line 2, skipping...
  81.             continue
  82.         fi
  83.  
  84.         case $dest in
  85.             X.*)    ;;
  86.             *)    echo $cfile line 2 isn\'t an Xfile, skipping...
  87.                 continue
  88.                 ;;
  89.         esac
  90.  
  91.         xfile=$source
  92.         echo X-file is $xfile
  93.  
  94.         # Make sure the X-file was the last line in the C-file
  95.         read type
  96.         if [ -n "$type" ]
  97.         then
  98.             echo $cfile has more than 2 lines, skipping...
  99.             continue
  100.         fi
  101.  
  102.         # Read the xfile looking for the destinations
  103.         dests=`egrep '^C rmail ' < $xfile | sed 's/^C rmail //'`
  104.  
  105.         if [ `echo $dests | wc -w` -eq 0 ]
  106.         then
  107.             echo $cfile isn\'t an rmail job, skipping...
  108.             continue
  109.         fi
  110.  
  111.         # Build newdests, which is the same as dests for users on
  112.         # machines other than the one being nuked, and is $sysname!user
  113.         # for users on the same system (this will result in mail being
  114.         # queued back onto the same system again).
  115.  
  116.         newdests=''
  117.         for user in $dests
  118.         do
  119.             if [ -n "`echo $user | grep !`" ]
  120.             then
  121.                 newdests="$newdests $user"
  122.             else
  123.                 newdests="$newdests $sysname!$user"
  124.             fi
  125.         done
  126.  
  127. #        echo Rerouting to $newdests
  128.  
  129.         # Re-send the mail, using aggressive rerouting
  130.         #smail -R -v $newdests < $dfile
  131.         # smail3.1 doesn't have -R
  132.         smail -v $newdests < $dfile
  133.  
  134.         # And kill off the old message
  135.         rm $cfile $dfile $xfile
  136.         echo Done
  137.     ) < $cfile
  138. done
  139. exit
  140.